package ru.ksu.ktk.diploma.sdi.util;

import java.util.ArrayList;
import java.util.List;

import ru.ksu.ktk.diploma.sdi.mapping.thesauri.ThesauriDescriptor;

public class DescriptorsUtil {
    private DescriptorsUtil() {
    }

    /**
     * get thesauri descriptors from list of repetitive descriptor identifiers
     * 
     * @param descriptorIdList
     * @return
     */
    public static List<ThesauriDescriptor> getThesauriDescriptors(List<String> descriptorIdList) {
        List<ThesauriDescriptor> descriptors = new ArrayList<ThesauriDescriptor>();
        for (String descriptorId : descriptorIdList){
            ThesauriDescriptor td = new ThesauriDescriptor(descriptorId);
            int descriptorIndex = descriptors.indexOf(td);
            if (descriptorIndex != -1){
                ThesauriDescriptor foundDescriptor = descriptors.get(descriptorIndex);
                foundDescriptor.increaseFrequency();
            }
            else{
                td.increaseFrequency();
                descriptors.add(td);
            }

        }

        return descriptors;
    }

}
